<?php
class FileDeleteComponent extends Object {

	var $components = array('Session');
	function DeleteTmp($savedfiles, $prefix) {
		$tmpfiles=array();
		foreach($this->Session->read('tmpfiles') as $file){			
			if (strpos($file, $prefix) !== false){
				$del = true;
				foreach($savedfiles as $savedfile){
					if (strpos($file, $savedfile) !== false){
						$del=false;
						break;
					}
				}
				if ($del){
					unlink($file);					
				}
			}else{
				$tmpfiles[]=$file;
			}
		}
		$this->Session->write('tmpfiles',$tmpfiles);
	}
}
?>
